home *** CD-ROM | disk | FTP | other *** search
- Path: rz.uni-karlsruhe.de!not-for-mail
- From: frick@i44sg1.informatik.uni-karlsruhe.de (Arne K. Frick)
- Newsgroups: comp.lang.tcl,comp.lang.c,comp.os.linux.development.system
- Subject: How do I get a (FILE *) from file descriptor?
- Date: 16 Apr 1996 17:27:18 +0200
- Organization: Universitaet Karlsruhe, FRG
- Sender: frick@i44sg1.info.uni-karlsruhe.de
- Message-ID: <yvdohosur3f.fsf@i44sg1.info.uni-karlsruhe.de>
- NNTP-Posting-Host: i44sg1.info.uni-karlsruhe.de
- Mime-Version: 1.0
- Content-Type: text/plain; charset=iso-8859-1
- Content-Transfer-Encoding: 8bit
- CC: drepper
- X-Newsreader: Gnus v5.1
-
- Background: A Tcl extension I use depends on using the (FILE *) form for
- describing its file handles. However, in Tcl-7.5b3 J. Ousterhout dropped
- support for the UNIX-specific command 'Tcl_GetOpenFile' which would take a
- Tcl handle and return the associated (FILE *). Now, all there is is a set
- of functions ultimately giving me an (int) as a file descriptor.
-
- I came up with the following piece of code that supposedly would use
- 'fdopen' to do the task. This seems to work fine for read-access, but when
- opening the file for writing 'fdopen' dumps core.
-
- chan = Tcl_GetChannel(interp, argv[3], &mode);
- if (chan == (Tcl_Channel) NULL) {
- Tcl_AppendResult(interp, "GdWriteCmd: Failure to get channel id", argv[3],
- (char *) NULL);
- return TCL_ERROR;
- }
- tf=Tcl_GetChannelFile(chan,TCL_WRITABLE);
- if (tf==(Tcl_File) NULL) {
- Tcl_AppendResult(interp, "GdWriteCmd: Failure to get file handle",
- (char *) NULL);
- return TCL_ERROR;
- }
- fd = (int) Tcl_GetFileInfo(tf, NULL);
- curStatus = fcntl(fd, F_GETFL);
- fprintf(stderr,"current status: %d\n",curStatus);
- if (curStatus<0) {
- Tcl_AppendResult(interp,"Gd_WriteCmd: file status error\n", (char *) NULL);
- }
-
- f = fdopen(fd,"w+");
- if (f == (FILE *) NULL) {
- Tcl_AppendResult(interp, "GdWriteCmd: Failure to get file descriptor",
- (char *) NULL);
- return TCL_ERROR;
- }
-
- Obviously, the Linux libc-5.2.8 should not core dump in 'fdopen' in the
- first place. This is a bug. The more interesting question, however, is
- whether my approach is feasible at all, or whether there is a better
- strategy other than to rewrite the existing library I'm interfacing to.
-
- Here's the configuration in question again:
-
- Linux Kernel 1.3.80
- libc-5.2.8
- Tcl-7.5b3/Tk-4.1b3
-
- I am trying to interface the gd1.2 library for GIF file
- creation/manipulation, just in case anyone asks. It uses (FILE *)'s all
- over the place.
-
-
- Any advice/help is certainly welcome.
-
-
-
- --
- Arne Frick |Tel.: 0721/608-4763
- Universitaet Karlsruhe |Fax: 0721/691462
- Vincenz-Priessnitz-Str. 3|EMail: Arne.Frick@informatik.uni-karlsruhe.de
- 76128 Karlsruhe |URL http://i44www.info.uni-karlsruhe.de/~frick
-